package edu.chl.da.ejb.core;

import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * This class respresent a seat on a airplane.
 * @author Jakob
 */
@Entity
@Table(name = "SEAT")
@NamedQueries({
    @NamedQuery(name = "Seat.findAll", query = "SELECT s FROM Seat s"),
    @NamedQuery(name = "Seat.findByAirplane", query = "SELECT s FROM Seat s WHERE s.seatPK.airplane = :airplane"),
    @NamedQuery(name = "Seat.findBySeatno", query = "SELECT s FROM Seat s WHERE s.seatPK.seatno = :seatno"),
    @NamedQuery(name = "Seat.findByRow", query = "SELECT s FROM Seat s WHERE s.seatPK.row = :row")})
public class Seat implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected SeatPK seatPK;
    @JoinColumn(name = "AIRPLANE", referencedColumnName = "ID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Airplane airplane1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "seat")
    private List<Reservation> reservationList;

    public Seat() {
    }

    public Seat(SeatPK seatPK) {
        this.seatPK = seatPK;
    }

    public Seat(int airplane, int seatno, int row) {
        this.seatPK = new SeatPK(airplane, seatno, row);
    }

    public SeatPK getSeatPK() {
        return seatPK;
    }

    public void setSeatPK(SeatPK seatPK) {
        this.seatPK = seatPK;
    }

    public Airplane getAirplane1() {
        return airplane1;
    }

    public void setAirplane1(Airplane airplane1) {
        this.airplane1 = airplane1;
    }

    public List<Reservation> getReservationList() {
        return reservationList;
    }

    public void setReservationList(List<Reservation> reservationList) {
        this.reservationList = reservationList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (seatPK != null ? seatPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Seat)) {
            return false;
        }
        Seat other = (Seat) object;
        if ((this.seatPK == null && other.seatPK != null) || (this.seatPK != null && !this.seatPK.equals(other.seatPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "edu.chl.da.ejb.core.Seat[seatPK=" + seatPK + "]";
    }

}
